<?php

namespace App\Admin\Controllers;

use App\Models\Sector;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class SectorController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('部门管理');
            $content->description('删除部门会把部门下的招聘职位一并删除');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('部门管理');
//            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('部门管理');
//            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Sector::class, function (Grid $grid) {

            $grid->id('ID')->sortable();
            $grid->disableExport();

            $grid->column('name', '职位部门');

            $grid->created_at('添加时间');
//            $grid->updated_at();

            $grid->filter(function ($filter) {
                $filter->disableIdFilter();
                $filter->like('name', '部门名字');
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Sector::class, function (Form $form) {

//            $form->display('id', 'ID');

            $form->text('name', '职位部门')
                ->attribute('maxlength', '50')
                ->help('说明：50个中文字符以内')
                ->rules('required|max:50');

            $form->display('created_at', '添加时间');
            $form->display('updated_at', '更新时间');
        });
    }
}
